/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */
#pragma once

#include "LrcAnalyzer.h"
#include "LrcWinShower.h"
#include "LrcDesktopShower.h"
#include "LrcShowFilter.h"

// CLrcShowFilter Class 
class CLrcShowFilter : public CTransInPlaceFilter, public ILrcShowFilter, public ISpecifyPropertyPages
{

      friend class CLrcShowFilterInputPin;
      friend class CLrcShowFilterOutputPin;

public:

      static CUnknown * WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);

      DECLARE_IUNKNOWN;

      // CTransInPlaceFilter Overrides
      virtual CBasePin *GetPin(int Idx);

      HRESULT CheckInputType(const CMediaType* mtIn)
      { UNREFERENCED_PARAMETER(mtIn);  return S_OK; }

      // Reveal our lrc show property setting interface.
      STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);

      // Virtual functions for interface ILrcShowFilter
      STDMETHODIMP get_IPin (IPin **ppPin);
      STDMETHODIMP put_MediaType(CMediaType *pmt);
      STDMETHODIMP get_MediaType(CMediaType **pmt);
      STDMETHODIMP get_State(FILTER_STATE *state);

      // Set show mode, 0 : window mode; 1 : desktop mode
      STDMETHODIMP SetShowMode(bool Mode);

      // Set property functions for window lrc show
      STDMETHODIMP SetWinShowWnd(HWND Handler);
      STDMETHODIMP SetWinAlignmentOpt(int Option);
	  STDMETHODIMP SetWinLineInterval(int Interval);
      STDMETHODIMP SetWinKaraokeMode(bool Mode);
	  STDMETHODIMP SetWinGradientMode(bool Mode);
	  STDMETHODIMP SetWinAutoResizeMode(bool Mode);
      STDMETHODIMP SetWinTopMostMode(bool Mode);
	  STDMETHODIMP SetWinFont(const LOGFONT* font);
	  STDMETHODIMP SetWinBgClr(COLORREF Clr);
      STDMETHODIMP SetWinFocusClr(COLORREF Clr);
   	  STDMETHODIMP SetWinUnFocusClr(COLORREF Clr) ;
      STDMETHODIMP SetWinLrcFile(const TCHAR * FullPath);    
	  STDMETHODIMP StartWinShow();
      STDMETHODIMP StopWinShow();
      STDMETHODIMP ReloadWinLrcFile(const TCHAR * FullPath);
      void LoadWinLrcFileHelper(const TCHAR * FullPath, bool Force);
      // Set property functions for desktop lrc show
      STDMETHODIMP SetDeskShowWnd(HWND Handler);
      STDMETHODIMP SetDeskShadowMode(bool Mode);
      STDMETHODIMP SetDeskOutlineMode(bool Mode);
      STDMETHODIMP SetDeskTopMostMode(bool Mode);
      STDMETHODIMP SetDeskTransMode(bool Mode);
      STDMETHODIMP SetDeskKaraokeMode(bool Mode);
  	  STDMETHODIMP SetDeskFont(const LOGFONT* Font);
	  STDMETHODIMP SetDeskBgClr(COLORREF Clr);
      STDMETHODIMP SetDeskLrcFile(const TCHAR * FullPath);
      STDMETHODIMP SetDeskBgTransparent(BYTE Transparent);
      STDMETHODIMP SetDeskLrcTransparent(BYTE Transparent);
      STDMETHODIMP SetDeskFocusClr(COLORREF Upper, COLORREF Mid, COLORREF Lower);
	  STDMETHODIMP SetDeskUnFocusClr(COLORREF Upper, COLORREF Mid, COLORREF Lower);
      STDMETHODIMP StartDesktopShow();
      STDMETHODIMP StopDesktopShow();
      STDMETHODIMP ReloadDeskLrcFile(const TCHAR * FullPath);
      void LoadDeskLrcFileHelper(const TCHAR * FullPath, bool Force);

      // Common set functions
      STDMETHODIMP SetDuration(long long Duration);
      STDMETHODIMP ChgToDeskShow();
      STDMETHODIMP ChgToWinShow();

      // To get ISpecifyPropertyPages interface
      STDMETHODIMP GetPages(CAUUID *pPages);

private:

      // Constructor
      CLrcShowFilter(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr);

      // Do the scroll real job in Transform
      HRESULT Transform(IMediaSample *pSample);

      // When the filter stops, we must stop our lrc show scroller(show start of lrc)
      STDMETHODIMP Stop();

         
      // When restart or slide, just remember the time offset
      HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
      {
          m_Offset = tStart/10000;
          return __super::NewSegment(tStart, tStop, dRate);
      }
    
      static int m_nInstanceCount;       // Total number of filter instances
      int m_nThisInstance;               // The index number of current instance
      CMediaType m_mtPreferred;          // Media type chosen from property sheet
      CCritSec m_FilterLock;             // To serialise access to the filter
      CLrcAnalyzer m_LrcParser;          // Lrc file parser
      CLrcWinShower m_WinShower;         // Lrc shower(in window)
      CLrcDesktopShower m_DesktopShower; // Lrc shower(on desktop)
      long long m_Offset;                // Time offset recorder
      bool m_ShowMode;                   // Lrc show mode, 0 : window mode; 1 : desktop mode
};

